package com.bwie.controller;

import com.bwie.common.domain.Role;
import com.bwie.common.domain.User;
import com.bwie.common.result.Result;
import com.bwie.service.SysUserServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: SysUserController
 * @Description: TODO
 * @version: v1.８.0
 * @author: 汪菲阳
 * @date: 2025/10/22 9:43
 */
@CrossOrigin
@RestController
@RequestMapping("/sysUser")
public class SysUserController {
    @Autowired
    private SysUserServcie sysUserServcie;

    /**
     * 根据手机号查询用户
     * @param user
     * @return
     */
    @PostMapping("selectUserByUserPhoneOrName")
    public Result<User> selectUserByUserPhoneOrName(@RequestBody User user){
        return Result.success(sysUserServcie.selectUserByUserPhone(user));
    }

    /**
     * 根据用户id查询角色信息
     * @param userId
     * @return
     */
    @GetMapping("selectRoleByUserId/{userId}")
    public Result<List<Role>> selectRoleByUserId(@PathVariable("userId") Integer userId){
        return Result.success(sysUserServcie.selectRoleByUserId(userId));
    }

    /**
     * 注册用户
     * @param user
     * @return
     */
    @PostMapping("registerUser")
    public Result registerUser(@RequestBody User user){
        sysUserServcie.registerUser(user);
        return Result.success();
    }
}
